<?php
session_start(); 
/*
 * This is the single entry point file. According to the page parameter in the URL, being get via $_GET, the appropriate php file will be included.
 * For example, index.php?page=login loads the login page. All forms for safety reasons (except search form) will use $_POST.
 *
 * models : Classes representing the entities. These are mostly, User, Order, Actor, DVDProduct etc.
 *          More of these are to be added as the project progresses
 * controllers : Invoked by the index.php, according to the get parameter. The main idea is 1 controller for each functionality
 * views : The html contentInvoked by their respective controllers. Login controller for example, loads the login view
 *
 * Main Philosophy: Controller fetches the input, then creates objects consistent with the model. The views then, invoked by the controllers,
 *                  use these objects in order to add content to the final page.
 */
 
/* initialize and load proper libs */
require_once('init.php');

$value = "member";
if (!isset($_SESSION['username'])) {
	require_once('models/Member.php');
	require_once('models/Order.php');
	require_once('views/RegisterView.php');
	require_once('views/ConfirmationMessageView.php');
	require_once('views/LoginView.php');
	require_once('views/ProfileView.php');
	require_once('controllers/MemberController.php');
	$controller = new MemberController($db);
}
else if (isset($_GET['page'])) {
	$value = $_GET['page'];
	if ($value == "dummy") {
		require_once('models/Dummy.php');
		require_once('views/DummyView.php');
		require_once('controllers/DummyController.php');
		$controller = new DummyController();
	}
	if ($value == "member") {
		require_once('models/Member.php');
		require_once('models/Order.php');
		require_once('views/RegisterView.php');
		require_once('views/ConfirmationMessageView.php');
		require_once('views/LoginView.php');
		require_once('views/ProfileView.php');
		require_once('controllers/MemberController.php');
		$controller = new MemberController($db);
	}
	else if ($value == "store_manager") {
		require_once('models/Movie.php');
		require_once('models/Director.php');
		require_once('models/Actor.php');
		require_once('models/Member.php');
		require_once('models/Category.php');
		require_once('views/ConfirmationMessageView.php');
		require_once('views/MovieListView.php');
		require_once('views/MovieInsertView.php');
		require_once('views/EditMovieView.php');
		require_once('views/StatisticsView.php');
		require_once('views/AwardsView.php');
		require_once('controllers/StorageManagerController.php');
		$controller = new StorageManagerController($db);
	}	
	else if ($value == "degrees") {
		require_once('models/Actor.php');
		require_once('views/DegreesOfSeparationView.php');
		require_once('controllers/DegreesOfSeparationController.php');
		require_once('lib/Serializer.php');
		$controller = new DegreesOfSeparationController($db);
	}
	else if ($value == "search") {
		require_once('models/Movie.php');
		require_once('models/Category.php');
		require_once('views/SearchView.php');
		require_once('views/EnhancedSearchView.php');
		require_once('controllers/SearchController.php');
		$controller = new SearchController($db);
	}
	else if ($value == "buy") {
		require_once('models/Member.php');
		require_once('models/Order.php');
		require_once('models/Movie.php');
		require_once('models/Actor.php');
		require_once('views/MovieView.php');
		require_once('views/ConfirmationMessageView.php');
		require_once('views/CheckoutView.php');
		require_once('controllers/BuyerController.php');
		$controller = new BuyerController($db);
	}
	else {
		echo '404 - not found';
		die();
	}
}
else {
	require_once('models/Member.php');
	require_once('models/Order.php');
	require_once('views/RegisterView.php');
	require_once('views/ConfirmationMessageView.php');
	require_once('views/LoginView.php');
	require_once('views/ProfileView.php');
	require_once('controllers/MemberController.php');
	$controller = new MemberController($db);
}

/* include master page file */
require_once('layout/page.php');
 
?>